package org.example.frame;

import org.example.panel.WelcomePanel;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MainFrame extends JFrame implements ActionListener {
    private JMenu menuUser = new JMenu("用户");
    private JMenuItem jMenuItemOpen = new JMenuItem("打开文件");
    private JMenuItem jMenuItemExit = new JMenuItem("退出");
    private JMenu menuExit = new JMenu("考试");
    private JMenuItem jMenuItemStart = new JMenuItem("开始考试");
    private JMenuItem jMenuItemScore = new JMenuItem("查询成绩");

    public MainFrame() throws HeadlessException {
        //
        addPanel();
        addMenu();
        addListener();
        initDB();
        this.setVisible(true);
    }

    private void initDB(){
        // jdbc
    }

    private void addListener(){
        jMenuItemExit.addActionListener(this);
        jMenuItemStart.addActionListener(this);
        jMenuItemScore.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        //..
    }


    private void addMenu(){
        menuUser.add(jMenuItemOpen);
        menuUser.addSeparator();
        menuUser.add(jMenuItemExit);

        menuExit.add(jMenuItemStart);
        menuExit.add(jMenuItemScore);


        JMenuBar jMenuBar = new JMenuBar();
        jMenuBar.add(menuUser);
        jMenuBar.add(menuExit);

        this.setJMenuBar(jMenuBar);
    }

    private void addPanel(){
        this.setTitle("【"  + "username" + "】");
        // 设置最大屏幕
        this.setSize(Toolkit.getDefaultToolkit().getScreenSize());
        // 设置最大化的屏幕（即点击最大的按钮）
        this.setSize(500,600);
        this.setExtendedState(JFrame.MAXIMIZED_BOTH);
        this.add(new WelcomePanel());
    }

    public static void main(String[] args) {
        new MainFrame();
    }


}
